package com.doctorliang.cheng.shopping.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.doctorliang.cheng.shopping.R;
import com.doctorliang.cheng.shopping.home.bean.ResultBeanData;
import com.doctorliang.cheng.shopping.utils.Constants;

import java.util.List;

/**
 * Created by CHENG on 2017/9/27.
 */

public class ChannelAdapter extends BaseAdapter {
    private final Context mcontext;
    private final List<ResultBeanData.ResultBean.ChannelInfoBean> channel_info;

    public ChannelAdapter(Context mcontext, List<ResultBeanData.ResultBean.ChannelInfoBean> channel_info) {
        this.mcontext = mcontext;
        this.channel_info = channel_info;
    }

    @Override
    public int getCount() {
        return channel_info.size();
    }

    @Override
    public Object getItem(int i) {
        return channel_info.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder  viewHolder;
        if (view == null) {
            view = View.inflate(mcontext, R.layout.item_channel1, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_icon = view.findViewById(R.id.iv_channel);
            viewHolder.tv_title = view.findViewById(R.id.tv_channel);
            view.setTag(viewHolder);
        } else {
            viewHolder  = (ViewHolder) view.getTag();
        }
        //根据位置填充数据
        ResultBeanData.ResultBean.ChannelInfoBean channelInfoBean = channel_info.get(i);
        viewHolder.tv_title.setText(channelInfoBean.getChannel_name());
        Glide.with(mcontext).load(Constants.BASE_URl_IMAGE+channelInfoBean.getImage()).into(viewHolder.iv_icon);
        return view;
    }
    static class ViewHolder{
        ImageView iv_icon;
        TextView tv_title;
    }
}
